<p class="Paragraph"><help:key-word value="relational databases" tag="kw66156_2"/>This command opens a window for definition of relationships between various database tables.</p>
</help:to-be-embedded>
<p class="Paragraph"><help:help-text value="visible" xmlns:help="http://openoffice.org/2000/help">Here you can link together tables from the current database through common data fields.</help:help-text> Click the <span class="T1">New relationship</span> icon to create the relationships, or simply drag and drop with the mouse.</p>
<p class="Paragraph">This function is only available for database relationships, i.e. you only see the command if you use <help:productname xmlns:help="http://openoffice.org/2000/help">%PRODUCTNAME</help:productname> as the front-end for a relational database.</p>
</span></th></tr></table>
<p class="Paragraph">If you start the <span class="T1">Relation design</span> command in the context menu of the table container, a window opens in which all the existing relationships between the tables of the current database are shown. <text:s text:c="" xmlns:text="http://openoffice.org/2000/text"/>If no relationships have yet been defined, or if you want to relate other tables of the database to each other, then click the <span class="T1">Add tables</span> icon. A <help:link Id="65934" xmlns:help="http://openoffice.org/2000/help">Dialog</help:link> opens in which you can select the tables that you want.</p>
<p class="Paragraph">If the relation window is open, the selected tables cannot be modified, even in table Design Mode. This ensures that it will not be possible to modify the tables while the relations are being created.</p>
</span></th></tr></table>
<p class="Paragraph">The selected tables are shown in the top area of the design view. You can remove a table window again via the context menu with the (Remove) key.</p>
<p class="Head2"><help:key-word value="other keys" tag="kw66156_6" xmlns:help="http://openoffice.org/2000/help"/><help:key-word value="primary keys" tag="kw66156_5" xmlns:help="http://openoffice.org/2000/help"/>Primary key and other key</p>
<p class="Paragraph">If you want to define a relation among the different tables, you should at least enter a <help:popup Id="65619" Eid="primaerschluessel" xmlns:help="http://openoffice.org/2000/help">primary key</help:popup> that clearly identifies a data field of the existing table. You can refer to the primary key from other table to access the data of this table. All data fields referring to this primary key will be identified as an <help:key-word value="external key" tag="kw66156_1" xmlns:help="http://openoffice.org/2000/help"/>external key.</p>
<p class="Paragraph">All data fields referring to a primary key will be identified in the table window by a small key symbol.</p>
<p class="Paragraph">Consider the "Item" table, for example, where each individual record can be defined by an item number. The "Item-Number" field is thus a unique key in this table, and is referred to as a "primary key".</p>
<p class="Paragraph">There is an additional table with the name "Orders" in the database. The number of the ordered item is assigned to each record in this table through an "Item-Number" field. This field is also a key field. It contains a key used to access the records of another table, in this case the "Item" table. For this reason, this field is referred to as the "foreign key".</p>
<p class="Paragraph">A relation is used to relate the primary key of the "Article" sheet and the other key of the "Orders" sheet.</p>
<p class="Head2">Define relations</p>
<p class="Paragraph"><help:key-word value="relations; creating" tag="kw66156_4" xmlns:help="http://openoffice.org/2000/help"/><help:key-word value="relations; deleting" tag="kw66156_3" xmlns:help="http://openoffice.org/2000/help"/>All existing relations are shown in the relations windows by a line that connects the primary and other key fields. You can add a relation by using drag and drop to drop the field of one table onto the field of the other table. A relation is removed again by pressing the (Remove) key (for which purpose it must be the current selection).</p>
<p class="Paragraph">Alternatively you can also click the <span class="T1">New relation</span> icon in the top area of the relation field and define the relation between two tables in a <help:link Id="66181" xmlns:help="http://openoffice.org/2000/help">Dialog</help:link>.</p>
<p class="Paragraph">If you use <help:productname xmlns:help="http://openoffice.org/2000/help">%PRODUCTNAME</help:productname> as the front-end for a relational database, the creation and deletion of relationships is not placed in an intermediate memory by <help:productname xmlns:help="http://openoffice.org/2000/help">%PRODUCTNAME</help:productname> but is forwarded directly to the external database.</p>
</span></th></tr></table>
<p class="Paragraph">By double-clicking a connection line you can assign certain properties to the relation. The <help:link Id="66181" xmlns:help="http://openoffice.org/2000/help"><span class="T1">Relations</span></help:link>dialog opens.</p>